package components {
	import mx.containers.Canvas;
	import mx.controls.Label;
	import mx.events.FlexEvent;
	
	public class Area extends Canvas {
		
        //------------------------------
        // labelName
        //------------------------------

        /**
         * name of the area
         */
        private var _labelName:String;

        public function get labelName():String {
            return _labelName;
        }

        public function set labelName(labelName:String):void {
            _labelName = labelName;
        }
        
        //------------------------------
        // borderSize
        //------------------------------

        /**
         * border thickness of the room
         */
        private static var _borderSize:int;

        public function get borderSize():int {
            if (_borderSize == 0) {
                _borderSize = getStyle("borderThickness");
            }
            return _borderSize;
        }
        
        /**
         * label control for area name
         */
        private var _label:Label;

        //------------------------------------------------------------
        //
        // constructor
        //
        //------------------------------------------------------------
        
		public function Area() {
			super();
			
			addEventListener(FlexEvent.CREATION_COMPLETE, onCreationComplete);
			addEventListener(FlexEvent.UPDATE_COMPLETE, onUpdateComplete);
			
			verticalScrollPolicy = "off";
			horizontalScrollPolicy = "off";
		}
		
		//------------------------------------------------------------
        //
        // event handlers
        //
        //------------------------------------------------------------
		
		private function onCreationComplete(e:FlexEvent):void {
			if (labelName) {
				_label = new Label();
				_label.text = labelName;
				
				addChild(_label);
			}
		}
		
		private function onUpdateComplete(e:FlexEvent):void {
			if (_label) {
				_label.setStyle("horizontalCenter", 0);
                
                if (_label.height <= height / 2) {
                    _label.setStyle("verticalCenter", height / 2 - _label.height);
                } else {
                    _label.setStyle("verticalCenter", 0);
                }
			}
		}

	}
}